<template>
	   <section>
		 <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
		  	<el-form :inline="true" :model="filters">
		  		<el-form-item>
		  			<el-input v-model="filters.name" placeholder="姓名"></el-input>
		  		</el-form-item>
		  		<el-form-item>
		  			<el-button type="primary" v-on:click="search">查询</el-button>
		  		</el-form-item>
		  		<!-- <el-form-item>
		  			<el-button type="primary" @click="handleAdd">新增</el-button>
		  		</el-form-item> -->
		  	</el-form>
		  </el-col>
		  
	       <el-col>
			   <el-tree :data="items" :props="defaultProps" @node-click="handleNodeClick"></el-tree>
		   </el-col>
	          
	       </section>
		  	
		  	
		  
	
		
		
	
	
</template>

<script>
	import util from '../../common/js/util'
	//import NProgress from 'nprogress'
	import { getUserListPage, removeUser, batchRemoveUser, editUser, addUser } from '../../api/api';
   
	export default {
		data() {
			return {
				     
					  userName:'',
				      items: [
				        ],

				 defaultProps: {
				          children: 'children',
				          label: 'label'
				        },

				filters: {
					name: ''
				},
				
			}
		},
		created:function(){
			this.filters.name = this.$route.query.userName
			this.search()
		},
		methods: {
			search:function(){
                    this.userName = this.filters.name
					this.getUsers()
				
			},
			getUsers:function() {
				
					let _this = this
					let params ={
					    params: {
					        userName:this.userName,
					       
					    }
					}
					let url = this.baseUrl +'/member/team'
					this.$http.get(url,params)
					.then((res)=>{
					        console.log(res)
							_this.items = res.body.data.list
							
					    }).catch(function (error) {
					        console.log(error)
					    });
			
			},
			handleNodeClick:function(data){
				console.log(data);
			},
			//性别显示转换
			formatSex: function (row, column) {
				return row.sex == 1 ? '男' : row.sex == 0 ? '女' : '未知';
			},
			handleCurrentChange(val) {
				this.page = val;
				this.getUsers();
			},
			
			
			//删除
			handleDel: function (index, row) {
				this.$confirm('确认删除该记录吗?', '提示', {
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					//NProgress.start();
					let para = { id: row.id };
					removeUser(para).then((res) => {
						this.listLoading = false;
						//NProgress.done();
						this.$message({
							message: '删除成功',
							type: 'success'
						});
						this.getUsers();
					});
				}).catch(() => {

				});
			},
			//显示编辑界面
			handleEdit: function (index, row) {
				this.editFormVisible = true;
				this.editForm = Object.assign({}, row);
			},
			//显示新增界面
			handleAdd: function () {
				this.addFormVisible = true;
				this.addForm = {
					name: '',
					sex: -1,
					age: 0,
					birth: '',
					addr: ''
				};
			},
			//编辑
			editSubmit: function () {
				this.$refs.editForm.validate((valid) => {
					if (valid) {
						this.$confirm('确认提交吗？', '提示', {}).then(() => {
							this.editLoading = true;
							//NProgress.start();
							let para = Object.assign({}, this.editForm);
							para.birth = (!para.birth || para.birth == '') ? '' : util.formatDate.format(new Date(para.birth), 'yyyy-MM-dd');
							editUser(para).then((res) => {
								this.editLoading = false;
								//NProgress.done();
								this.$message({
									message: '提交成功',
									type: 'success'
								});
								this.$refs['editForm'].resetFields();
								this.editFormVisible = false;
								this.getUsers();
							});
						});
					}
				});
			},
			//新增
			addSubmit: function () {
				this.$refs.addForm.validate((valid) => {
					if (valid) {
						this.$confirm('确认提交吗？', '提示', {}).then(() => {
							this.addLoading = true;
							//NProgress.start();
							let para = Object.assign({}, this.addForm);
							para.birth = (!para.birth || para.birth == '') ? '' : util.formatDate.format(new Date(para.birth), 'yyyy-MM-dd');
							addUser(para).then((res) => {
								this.addLoading = false;
								//NProgress.done();
								this.$message({
									message: '提交成功',
									type: 'success'
								});
								this.$refs['addForm'].resetFields();
								this.addFormVisible = false;
								this.getUsers();
							});
						});
					}
				});
			},
			selsChange: function (sels) {
				this.sels = sels;
			},
			//批量删除
			batchRemove: function () {
				var ids = this.sels.map(item => item.id).toString();
				this.$confirm('确认删除选中记录吗？', '提示', {
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					//NProgress.start();
					let para = { ids: ids };
					batchRemoveUser(para).then((res) => {
						this.listLoading = false;
						//NProgress.done();
						this.$message({
							message: '删除成功',
							type: 'success'
						});
						this.getUsers();
					});
				}).catch(() => {

				});
			}
		},
		mounted() {
			this.getUsers();
		}
	}

</script>

<style scoped>

</style>
